package com.test.reggieadmin.model.employee;

import com.test.reggieadmin.base.BaseObserver;
import com.test.reggieadmin.base.BasePresenter;
import com.test.reggieadmin.bean.BaseBean;
import com.test.reggieadmin.bean.EmployeeDetailsBean;

import java.util.Map;

public class AddEmployeePrensenter extends BasePresenter<AddEmployeeView> {
    public AddEmployeePrensenter(AddEmployeeView baseView) {
        super(baseView);
    }

    /**
     * 添加员工
     *
     * @param map
     */
    public void save(Map<String, Object> map) {
        addDisposable(apiServer.save(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.saveData(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 修改员工信息
     *
     * @param map
     */
    public void update(Map<String, Object> map) {
        addDisposable(apiServer.update(map), new BaseObserver<BaseBean>() {
            @Override
            public void onSuccess(BaseBean bean) {
                baseView.updateData(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }

    /**
     * 根据id查询员工信息
     *
     * @param id
     */
    public void employeeDetails(String id) {
        addDisposable(apiServer.employeeDetails(id), new BaseObserver<EmployeeDetailsBean>() {
            @Override
            public void onSuccess(EmployeeDetailsBean bean) {
                baseView.employeeDetailsData(bean);
            }

            @Override
            public void onError(String msg) {
                baseView.onError(msg);
            }
        });
    }
}
